var tgHtml='';
tgHtml += '<div class="form-div"><form class="layui-form" id="fomr">';
tgHtml += '<div class="layui-form-item"><label class="layui-form-label">报单中心</label><div class="layui-input-block"><input type="text" name="p_agent" placeholder="请输入父级报单中心编号" autocomplete="off" class="layui-input"></div></div>';
tgHtml += '<input type="hidden" name="token" value="' + token + '">';
tgHtml += '<input type="hidden" name="status" value="1">';
tgHtml += '<input type="hidden" name="id">';
tgHtml += '</form></div>';

layui.use('table', function() {
	var table = layui.table,layer=layui.layer;
	
	table.on('checkbox(table)', function(obj){
		var checkStatus = table.checkStatus('idTest'),data = checkStatus.data;
         if(data.length>0){
         	$(".center-nav a.hb-bnt").removeClass("hov-n").addClass("hov");
         }else{
         	$(".center-nav a.hb-bnt").removeClass("hov").addClass("hov-n");
         }
     });
	var $ = layui.$, active = {
	 	handle: function(){
	      var checkStatus = table.checkStatus('idTest'),data = checkStatus.data;
	      var stx=$(this).attr("data-st");
	      var myArray = new Array();
			for(var i = 0; i < data.length; i++) {
				myArray.push(data[i].id)
			}
			layer.alert('您确定要驳回审核', {
				icon: 2,
				btn: ['确定', '关闭'],
				btn1: function() {
					$.ajax({
						type: 'post',
						dataType: 'json',
						url: czSrc,
						data: {
							status:stx,
							token: token,
							id: myArray
						},
						success: function(data) {
							var code = data.code;
							var msg = data.msg;
							if(code == 1) {
								layer.close(layer.index)
								layer.alert(msg, {
									icon: 1
								}, function() {
									location.reload();
								})
							} else {
								layer.close(layer.index)
								layer.alert(msg, {
									icon: 5
								})
							}
						}
					})
				}
			})
	    }
	 }
	 $('.right-center .right-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	});
	
	layer.msg('数据加载中...', {
		icon: 16,
		shade: 0.3,
		success: function() {
			$.ajax({
				type: 'post',
				dataType: 'json',
				url: listSrc,
				success: function(data) {
					table.render({
						elem: '#centet-cen',
						height: $(".center-tab").height(),
						id:'idTest',
						cols: [
							[ //标题栏
							    {
									type: 'checkbox'
								},{
									field: 'id',
									title: 'ID',
									width: 100
								}, {
									field: 'mid',
									title: '会员编号',
									width: 100
								}, {
									field: 'title',
									title: '标题',
									width: 160
								}, {
									field: 'content',
									title: '内容'
								}, {
									field: 'create_time',
									title: '提交时间',
									width: 160
								}, {
									field: 'status_remark',
									title: '状态',
									width: 100
								}, {
									field: 'oper',
									title: '操作',
									width: 300,
									minWidth: 160,
									toolbar: '#barDemo'
								}

							]
						],
						data: data,
						limit: 200
					});
					var pageHtml = data.page_html;
					$(".paging").html(pageHtml);
					layer.close(layer.index)
				}
			});
		}
	});
	table.on('tool(table)', function(obj) {
		var data = obj.data;
		if(obj.event === 'tgfun') {
			layer.open({
				type: 1,
				title: "设置的父级报单中心",
				area: ['550px', '190px'], //宽高
				maxmin: true,
				resize: true,
				content: tgHtml,
				btn: ['提交', '关闭'],
				btn1: function() {
					var Adata = $("#fomr").serialize();
					$.ajax({
						type: 'post',
						dataType: 'json',
						url: czSrc,
						data: Adata,
						success: function(data) {
							var code = data.code;
							var msg = data.msg;
							if(code == 1) {
								layer.close(layer.index)
								layer.alert(msg, {
									icon: 1
								}, function() {
									location.reload();
								})
							} else {
								layer.alert(msg, {
									icon: 5
								})
							}
						}
					})
				}
			});
			$("#fomr input[name=id]").val(data.id);
		}
	});
	
	
})

layui.use(['form', 'layedit', 'laydate'], function(){
	 var form = layui.form,layer = layui.layer,layedit = layui.layedit,laydate = layui.laydate;
	laydate.render({
		elem: '#start'
	});
	laydate.render({
		elem: '#end'
	});
})


$(function() {
	$('#screen-form').formEdit(seet);
	$("#Expbnt").click(function(){
		$("#screen-form").attr("action",ExpSrc);
	})
	$("#ScreenBnt").click(function(){
		$("#screen-form").attr("action",'');
	})
	
})
